/* IMPORTANT!
   This file is loaded dynamically when the inline search is invoked.
   So don't put main popup's stuff here. */

.search-results-shown {
  body {
    overflow-y: auto;
  }
  #installed-wrapper, #main-actions, #popup-options {
    flex-shrink: 0;
  }
}

#pct {
  --h: var(--outer-padding);
  font-size: var(--h);
  line-height: var(--h);
  margin-top: calc(var(--h) * -1);
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  color: var(--accent-2);
  z-index: 2;
  > * {
    transition: opacity .5s;
  }
  > :empty {
    opacity: 0;
  }
  > :nth-child(n + 2) {
    margin-left: 1em;
  }
  :is(.styles-last, .search-results-shown.styles-first) & {
    margin: 0 0 calc(var(--h) * -1);
  }
}

#search-results {
  background: linear-gradient(
    var(--c95) 2em,
    var(--c90) 110px /* nav and search params */,
    var(--c70) 220px /* middle of the first thumbnail */,
    var(--c70) calc(100% - 110px) /* middle of the last thumbnail */,
    var(--c85) calc(100% - 30px)) /* stop at the bottom nav */;
  padding-bottom: 0 !important;
  border-top: 1px solid var(--c80);
}

#search-results-error {
  color: #fff;
  background-color: var(--red1);
  font-weight: bold;
  padding: 5px;
  text-align: center;
  + :not([hidden]) {
    margin-top: var(--outer-padding);
  }
}

#search-results-list {
  position: relative;
  min-height: 200px;
}

.search-result,
.search-result-empty {
  --pad: 8px;
  position: relative;
  padding: var(--pad);
  min-height: 160px;
}

.search-result {
  box-shadow: 1px 1px 10px rgba(0, 0, 0, .75);
  border-radius: 4px;
  border: 1px solid var(--c50);
  background-color: var(--c95);
  &:nth-last-child(n + 2) {
    margin-bottom: calc(2 * var(--pad));
  }
  &:hover {
    border-color: var(--fg);
    background-color: var(--c90);
  }
}

#search-results {
  .lds-spinner {
    transform: scale(.5);
    filter: invert(1) drop-shadow(1px 1px 3px var(--fg));
  }
  .search-result-empty .lds-spinner {
    filter: opacity(.2);
  }
}

.search-result-screenshot {
  height: 140px;
  width: 100%;
  object-fit: cover;
  cursor: pointer;
}

.search-result-title {
  display: flex;
  align-items: center;
  margin-bottom: .5em;
  color: var(--c30);
  overflow-wrap: break-word;
  & img {
    width: 20px;
    height: 20px;
    margin: -6px 4px -6px 0;
  }
  & span {
    font-size: var(--font-size);
    font-weight: 600;
  }
  .search-result:hover & {
    color: var(--fg);
  }
}

.search-result-info {
  position: relative;
}

.search-result-status {
  top: 0;
  left: 0;
  right: 0;
  line-height: 18px;
  text-align: center;
  position: absolute;
  background-color: hsla(180, 100%, 27%, .75);
  color: var(--bg);
  transition: background-color .5s;
  pointer-events: none;
  .search-result-screenshot:hover ~ & {
    background-color: hsla(180, 100%, 27%, 1);
    color: var(--bg);
  }
}
.search-result[data-no-image] {
  .search-result-status {
    line-height: 140px;
  }
  &:not([data-installed]) .search-result-status {
    background-color: rgba(128, 128, 128, .1);
    color: currentColor;
  }
  .search-result-screenshot {
    opacity: 0;
  }
}

.search-result-actions {
  bottom: 20px;
  text-align: center;
  z-index: 10;
  position: absolute;
  width: 100%;
}

.search-result {
  &[data-installed] {
    box-shadow: 1px 1px 10px darkcyan;
    border-color: darkcyan;
  }
  &:not([data-installed]) {
    .search-result-actions {
      transition: opacity .5s;
    }
    &:not(:hover) .search-result-actions {
      opacity: 0;
    }
  }
}
.search-result-actions button {
  box-shadow: 2px 2px 20px var(--fg);
  white-space: nowrap;
  margin: 3px;
}
.search-result[data-no-image] .search-result-actions button {
  box-shadow: none;
}
.search-result-install,
.search-result-uninstall,
.search-result:not([data-installed][data-customizable]) .search-result-customize {
  display: none;
}
.search-result.not-matching .search-result-customize {
  opacity: .5;
}

.search-result-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  bottom: 0;
  position: absolute;
  width: 100%;
  line-height: 16px;
  margin: 0;
  padding-bottom: 3px;

  &::before {
    transition: .25s;
    background-color: var(--c95);
    opacity: .65;
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 22px;
    z-index: 1;
  }

  > * {
    z-index: 2;
  }

  .search-result:hover &::before {
    background-color: var(--c90);
    opacity: 1;
  }

  & dt {
    display: none;
  }

  & dd {
    margin: 0;
  }

  & [data-type="author"] {
    max-width: 30%;
    & a {
      color: inherit;
      font-weight: bold;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      display: block;
    }
  }


  & [data-type="rating"] {
    & dd {
      text-align: center;
      font-weight: bold;
    }
    &[data-class="good"] dd {
      color: darkgreen;
    }
    &[data-class="okay"] dd {
      color: darkgreen;
    }
    &[data-class="bad"] dd {
      color: darkred;
    }
    &[data-class="none"] dd {
      /* Keeping an empty rule so customizers can easily tweak it */
    }
  }

  :is([data-type="weekly"], [data-type="total"]) {
    text-align: right;
    & dd {
      font-weight: bold;
    }
  }
}

.search-result-description:not(:empty) {
  font-size: 90%;
  margin-bottom: calc(var(--pad) / -2);
  max-height: 25vh;
  overflow-y: auto;
  overflow-wrap: break-word;
}

.not-matching-explainer {
  padding: var(--pad);
  margin: calc(-1 * var(--pad)) calc(-1 * var(--pad)) var(--pad);
  border-bottom: 2px solid hsla(25, 100%, 60%, .5);
  background-color: hsla(25, 100%, 60%, .2);
  cursor: help;
}

[data-error] {
  &, &:hover {
    border: calc(var(--pad) / 2) solid red;
    border-radius: var(--pad);
    padding: calc(var(--pad) / 2);
    background: hsl(0, 90%, 85%);
  }
  &::after {
    content: attr(data-error);
    display: block;
    color: hsl(0, 100%, 8%);
    font-weight: bold;
    padding-top: var(--pad);
    hyphens: auto;
    white-space: pre-wrap;
  }
  .search-result-meta {
    background: hsla(0, 100%, 90%, .80);
  }
}
.search-results-nav {
  text-align: center;
  word-break: keep-all;
  line-height: 24px;
  font-size: 16px;
  background-color: var(--bg);
  margin: 0 calc(-1 * var(--outer-padding)) .5em;
  &[data-type="top"] {
    border-bottom: var(--border);
    padding: .25em 0 0;
  }
  &[data-type="bottom"] {
    border-top: var(--border);
    padding: .25em 0;
    margin-top: 1em;
    margin-bottom: 0;
  }
  & label {
    vertical-align: middle;
    -moz-user-select: none;
    user-select: none;
  }
  [data-type="page"] {
    font-weight: bold;
  }
  #search-results & button {
    background: none;
    border: none;
    padding: 0 .5rem;
    margin: 0 .5rem;
    font-size: 18px;
    vertical-align: middle;
    cursor: pointer;
    &:disabled {
      cursor: auto;
      opacity: .25;
      pointer-events: none;
    }
    &:not(:disabled):hover {
      text-shadow: 0 1px 4px rgba(0, 0, 0, .5);
    }
  }
}

#search-params {
  display: flex;
  position: relative;
  --t: .5rem;
  --x: calc(var(--t) / 2);
  margin: calc(-1 * var(--t)) calc(-1 * var(--x)) calc(2.5 * var(--t));
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  > * {
    margin: var(--t) var(--x) 0;
  }
  :is(input, select) {
    background-color: var(--c98);
  }
  :is(input, select):focus {
    background-color: var(--bg);
  }
}
#search-query {
  min-width: 4em;
  margin-right: .5em;
  flex: 1 1 4em;
}
#search-years {
  text-align: center;
  min-width: 12em;
}

@media (width < 400px) {
  #search-years {
    width: 100%;
  }
}

@media (min-width: 400px) {
  .search-result {
    --col: 3;
    width: calc((100% - var(--pad) * (var(--col) - 1)) / var(--col));
    display: inline-block;
    vertical-align: top;
    box-sizing: border-box;
    margin-right: var(--pad);
    @media (width < 600px) {
      --col: 2;
      &:nth-child(even) {
        margin-right: 0;
      }
    }
  }
}
@media (min-width: 600px) {
  .search-result:nth-child(3n) {
    margin-right: 0;
  }
}
